﻿namespace Tw.Trains.Domain
{
    public enum AttributeType
    {
        Distance,
        Stops
    }

    public enum Operate
    {
        Less,
        LessOrEquals
    }

    /// <summary> 线路条件 </summary>
    public class TripCondition
    {
        public int Condition { get; set; }
        public AttributeType Type { get; set; }
        public Operate Operate { get; set; }

        public TripCondition(int condition, AttributeType type = AttributeType.Distance, Operate operate = Operate.Less)
        {
            Condition = condition;
            Type = type;
            Operate = operate;
        }

        public bool Verify(TripAttribute attr)
        {
            if (attr == null)
                return false;
            int value;
            switch (Type)
            {
                case AttributeType.Distance:
                    value = attr.Distance;
                    break;
                case AttributeType.Stops:
                    value = attr.Stops;
                    break;
                default:
                    return false;
            }
            switch (Operate)
            {
                case Operate.Less:
                    return value < Condition;
                case Operate.LessOrEquals:
                    return value <= Condition;
                default:
                    return false;
            }
        }
    }
}

